package com.lupengning.es.test.index;

import java.io.IOException;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;

public class ESTest_Index_Create {

  public static void main(String[] args) throws IOException {
    RestHighLevelClient esClient = new RestHighLevelClient(
        RestClient.builder(new HttpHost("192.168.56.10", 9200, "http"))
    );

    CreateIndexRequest request = new CreateIndexRequest("employee");
    CreateIndexResponse response = esClient.indices()
        .create(request, RequestOptions.DEFAULT);
    boolean responseAcknowledged = response.isAcknowledged();
    System.out.println("索引创建是否成功：" + responseAcknowledged);

    esClient.close();
  }
}
